//
//  KLRecommendCell.m
//  BIBILILI
//
//  Created by juwangkeji on 2018/7/13.
//  Copyright © 2018年 WTF. All rights reserved.
//

#import "KLRecommendCell.h"
#import <UIImageView+WebCache.h>
@interface KLRecommendCell()
@property(nonatomic,weak) UIImageView * m_ImageView;
@property(nonatomic,weak) UILabel * m_title;
@property(nonatomic,weak) UILabel * m_Typetitle;
@property(nonatomic,weak) UILabel * m_DeltypeTitle;

@end

@implementation KLRecommendCell



-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    self.backgroundColor = [UIColor whiteColor];
    UIImageView * imgV = [[UIImageView alloc] init];
    imgV.image = [UIImage imageNamed:@"1"];
    UILabel * mainTitle = [[UILabel alloc] init];
    mainTitle.textAlignment = NSTextAlignmentLeft;
    mainTitle.font = [UIFont systemFontOfSize:14];
    mainTitle.numberOfLines = 2;
    
    UILabel * typeT = [[UILabel alloc] init];
    typeT.textAlignment = NSTextAlignmentLeft;
    typeT.font = [UIFont systemFontOfSize:12];
    typeT.textColor = [UIColor lightGrayColor];
    
    UILabel * typeDT = [[UILabel alloc] init];
    typeDT.textAlignment = NSTextAlignmentRight;
    typeDT.font = [UIFont systemFontOfSize:12];
    typeDT.textColor = [UIColor lightGrayColor];
    
    [self addSubview:imgV];
    [self addSubview:mainTitle];
    [self addSubview:typeT];
    [self addSubview:typeDT];
    self.m_ImageView = imgV;
    self.m_title = mainTitle;
    self.m_Typetitle = typeT;
    self.m_DeltypeTitle = typeDT;
    
    self.backgroundColor = [UIColor whiteColor];
}


-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.m_ImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self).insets(UIEdgeInsetsMake(0, 0, __KNewSize(140), 0));
    }];
    
    [self.m_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self.m_ImageView.mas_bottom).with.offset(25);
        make.width.mas_equalTo(self.mas_width).with.offset(__KNewSize(-40));
        make.height.mas_equalTo(40);
    }];
    
    [self.m_Typetitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.m_title.mas_left);
        make.bottom.mas_equalTo(self.mas_bottom).with.offset(__KNewSize(-10));
        make.width.mas_equalTo(__KNewSize(170));
        make.height.mas_equalTo(20);
    }];
    
    [self.m_DeltypeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.m_title.mas_right);
        make.centerY.mas_equalTo(self.m_Typetitle);
        make.width.mas_equalTo(__KNewSize(180));
        make.height.mas_equalTo(20);
    }];
}

-(void)drawRect:(CGRect)rect{
    CGRect m_Frame = self.m_ImageView.bounds;
    UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
    UIBezierPath * maskPath = [UIBezierPath bezierPathWithRoundedRect:m_Frame byRoundingCorners:corners cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer * maskLayer =[[CAShapeLayer alloc] init];
    maskLayer.frame = self.m_ImageView.bounds;
    maskLayer.path = maskPath.CGPath;
    self.m_ImageView.layer.mask = maskLayer;
    
    UIBezierPath * maskPath2 = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10];
    CAShapeLayer * maskLayer2 =[[CAShapeLayer alloc] init];
    maskLayer2.frame = self.bounds;
    maskLayer2.path = maskPath2.CGPath;
    self.layer.mask = maskLayer2;
}


@end
